import App from './App'
import store from './store/index.js'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App,
	store
})
app.$mount()
// #endif

import uView from 'uview-ui'
Vue.use(uView)

//注册更新组件
import update from '@/components/update.vue'
Vue.component('update',update)

//uview全局配置
uni.$u.setConfig({
	props:{
		input:{
			maxlength:20
		},
		textarea:{
			maxlength:200
		},
		button:{
			throttleTime:1500
		},
		code:{
			keepRunning:true
		}
	}
})

import {
	$http
} from '@escook/request-miniprogram'

import global from 'common/global.js'

uni.$http = $http
// 配置请求根路径
$http.baseUrl = global.api

// 请求开始之前做一些事情
$http.beforeRequest = function(options) {
	let obj = {}
	// let tokenName = uni.getStorageSync('tokenName');
	let token = uni.getStorageSync('token');
	obj.token = token
	options.header = obj
	uni.showLoading({
		title: '数据加载中...',
	})

}

// 请求完成之后做一些事情
$http.afterRequest = function(res) {
	//token失效
	if (res.data.code == 500) {
		uni.clearStorageSync()
		uni.navigateTo({
			url: '/pages/login'
		})
		uni.showToast({
			icon: 'none',
			title: '登陆失效,请重新登陆'
		})
	} else {
		if (res.data.code != 200) {
			uni.showToast({
				icon: 'none',
				title: res.data.message
			})
		}
	}
	uni.hideLoading()
}


// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif